clear all
set more off
cd "~/data"

****************
**************** LOAD DATA
****************

use "~/characteristics1930.dta"

merge 1:1 county using "~/pop1910.dta", nogen
merge 1:1 county using "~/pop1920.dta", nogen
merge 1:1 county using "~/pop1930.dta", nogen

merge 1:1 county using "~/mex_pop1910.dta", nogen
merge 1:1 county using "~/mex_pop1930.dta", nogen
merge 1:1 county using "~/mex_pop1940.dta", nogen

merge 1:1 county using "~/native_emp_by_group_2groups_1930.dta", nogen
merge 1:1 county using "~/native_emp_by_group_2groups_1930_male.dta", nogen
merge 1:1 county using "~/native_emp_by_group_2groups_1940.dta", nogen
merge 1:1 county using "~/native_emp_by_group_2groups_1940_male.dta", nogen

merge 1:1 county using "~/native_emp1910.dta", nogen
merge 1:1 county using "~/native_emp1930.dta", nogen
merge 1:1 county using "~/native_emp1940.dta", nogen

merge 1:1 county using "~/native_male_emp1930.dta", nogen
merge 1:1 county using "~/native_male_emp1940.dta", nogen

merge 1:1 county using "~/native_pop1920.dta", nogen
merge 1:1 county using "~/native_pop1930.dta", nogen
merge 1:1 county using "~/native_pop1940.dta", nogen

merge 1:1 county using "~/wage1910.dta", nogen
merge 1:1 county using "~/wage1930.dta", nogen
merge 1:1 county using "~/wage1930_male.dta", nogen
merge 1:1 county using "~/wage1940.dta", nogen
merge 1:1 county using "~/wage1940_male.dta", nogen

merge 1:1 county using "~/urban_share.dta", nogen
merge 1:1 county using "~/mf_agric_share.dta", nogen
merge 1:1 county using "~/police.dta", nogen

merge 1:1 county using "fishback/fishback.dta", nogen

merge 1:1 county using "~/mex_distance_clean.dta", nogen
merge 1:1 county using "~/railroad_clean.dta", nogen
merge 1:1 county using "~/railroad_distance_clean.dta", nogen

merge 1:1 county using "~/county_sea_crosswalk_1910.dta", nogen

merge 1:1 county using "~/new_controls.dta", nogen

sum

****************
**************** KEEP ONLY RELEVANT STATES
****************

drop statefip
tostring county, gen(fips)
replace fips = "0" + fips if strlen(fips) == 4
gen statefip = substr(fips,1,2), after(fips)
destring statefip, replace

keep if inlist(statefip, 41, 8, 32, 49, 40, 22, 5, 4, 6, 48, 35)
unique statefip
assert r(unique) == 11

order fips county statefip sea pop* mex_pop* s_* *emp* *wage*

****************
****************
****************

gen dmex = -(mex_pop40 - mex_pop30)/pop30

gen demp = (emp40_native - emp30_native)/pop30
gen demp_low = (emp40_native_low - emp30_native_low)/pop30
gen demp_high = (emp40_native_high - emp30_native_high)/pop30
gen demp_male = (emp40_male_native - emp30_male_native)/pop30
gen demp_male_low = (emp40_native_low_male - emp30_native_low_male)/pop30
gen demp_male_high = (emp40_native_high_male - emp30_native_high_male)/pop30

gen dpop_native = (pop40_native - pop30_native)/pop30

gen dwage_agg = wage40 - wage30
gen dwage_male_agg = wage40_male - wage30_male

gen mex_share10 = mex_pop10/pop10

gen lnpop30 = log(pop30)
gen pop_dens = log(pop30/area30)

gen pre_demp_agg = (emp30_native - emp10_native)/pop10
gen pre_dpop_agg = (pop30_native - pop20_native)/pop20
gen pre_dwage_agg = wage30 - wage10

gen rail2 = railroad == 2, after(railroad)

replace miles_to_mex = miles_to_mex / 100

drop area30 major minor

****************
**************** LABELS
****************

label var dmex "$ MexPopDrop_c $"
label var ndexp "New Deal"
label var dustbowl "Dust Bowl"
label var extreme_phdi "Extreme Weather"
label var lnpop30 "Log Population"
label var rldf3329 "Retail Growth"
label var mex_share10 "Mex. Share 1910"
label var rail2 "Major Railroad"
label var aaa "Agric Adjust Admin grants"
label var pubwor "public works grants"
label var loan "total loans"
label var relief "total relief grants"

****************
**************** GENERATE SOME INSTRUMENTAL VARIABLES
****************

qui sum miles_to_rr, d
gen close_to_rr = miles_to_rr < r(p50)
gen close_to_rr_interact = close_to_rr * mex_share10

gen rail_interact = rail2 * mex_share10
gen pctdem_interact = pctdem * mex_share10

****************
**************** SAVE
****************

order fips county name statefip sea pop* mex_pop* lnpop30 s_* *emp* *wage* d* pre* mex_share10 ndexp extreme_phdi rldf3329 pctdem miles* railroad

sum

compress

saveold "~/aggregate_nber.dta", replace version(12)
